package com.ourteam.product.ui.dao.impl;

import com.ourteam.product.ui.dao.IProductUIPageParamDAO;
import com.ourteam.product.ui.dao.ProductUIPageParam;
import com.ourteam.product.ui.dao.ProductUIPageParamDAOQueryBean;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import net.dao.AbstractSpringDAO;
import net.dao.DataAccessObjectHelper;
import org.apache.commons.beanutils.PropertyUtils;
import org.apache.commons.lang.StringUtils;
import org.springframework.jdbc.core.RowMapper;

/**
 * Template Name : DAO服务对象 Template Version : 1 Template Last Modfiy Date : Fri Nov 17 11:00:11 CST
 * 2017 Auto Generate Date : 2018-12-14 15:15:20 Warning ! This file will be overwrite when
 * regenerate !
 */
public class AbstractProductUIPageParamDAOJdbcImpl extends AbstractSpringDAO
    implements IProductUIPageParamDAO {

  public static final String[] ENTITY_FIELDS =
      new String[] {
        Id,
        PageId,
        PageParamId,
        PageParamValue,
        Status,
        Remarks,
        PageParamValueId,
        ParamCode,
        ParamDesc,
        ParamInputType
      };

  public static final String[] ENTITY_PROPERTIES =
      new String[] {
        _DataObjectProperty.Id,
        _DataObjectProperty.PageId,
        _DataObjectProperty.PageParamId,
        _DataObjectProperty.PageParamValue,
        _DataObjectProperty.Status,
        _DataObjectProperty.Remarks,
        _DataObjectProperty.PageParamValueId,
        _DataObjectProperty.ParamCode,
        _DataObjectProperty.ParamDesc,
        _DataObjectProperty.ParamInputType
      };

  public static final String[] ENTITY_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_AUTO_GEN_PK_FIELDS = new String[] {Id};

  public static final String[] ENTITY_UNIQUE_FIELDS = new String[] {};

  private static String relatedJoinSQL = null;

  private static String basicFilterSQL = null;

  private DataAccessObjectHelper<ProductUIPageParam, ProductUIPageParamDAOQueryBean> daoHelper;

  public AbstractProductUIPageParamDAOJdbcImpl() {
    super();
    daoHelper =
        new DataAccessObjectHelper<ProductUIPageParam, ProductUIPageParamDAOQueryBean>(this);
  }

  protected String getEntityName() {
    return EntityName;
  }

  protected String[] getEntityFields() {
    return ENTITY_FIELDS;
  }

  protected String[] getEntityProperties() {
    return ENTITY_PROPERTIES;
  }

  protected String[] getEntityPKFields() {
    return ENTITY_PK_FIELDS;
  }

  protected String[] getEntityAutoGenPKFields() {
    return ENTITY_AUTO_GEN_PK_FIELDS;
  }

  protected String[] getEntityUniqueFields() {
    return ENTITY_UNIQUE_FIELDS;
  }

  protected String getBaiscQueryFilter() {

    if (basicFilterSQL == null) {
      StringBuffer basicFilterSQLbuffer = new StringBuffer();

      basicFilterSQL = basicFilterSQLbuffer.toString();
    }

    return basicFilterSQL;
  }

  protected String getRelatedJoinSQL() {

    if (relatedJoinSQL == null) {
      StringBuffer relatedJoinSQLBuffer = new StringBuffer();

      relatedJoinSQLBuffer
          .append(" LEFT JOIN ")
          .append(com.ourteam.product.ui.dao.IProductUIPageTemplateParamDAO.EntityName)
          .append(" RELATED_49ZXCY_ProductUIPageTemplateParam ");

      relatedJoinSQLBuffer.append(" ON ( ");

      relatedJoinSQLBuffer.append(
          StringUtils.replace(
              com.ourteam.product.ui.dao.IProductUIPageTemplateParamDAO.Id,
              com.ourteam.product.ui.dao.IProductUIPageTemplateParamDAO.EntityName + ".",
              "RELATED_49ZXCY_ProductUIPageTemplateParam."));
      relatedJoinSQLBuffer.append(" = ").append(PageParamId);

      relatedJoinSQLBuffer.append(" ) ");

      relatedJoinSQL = relatedJoinSQLBuffer.toString();
    }

    return relatedJoinSQL;
  }

  /**
   * Check Data Unique
   *
   * @param aProductUIPageParam
   * @throws Exception
   */
  public boolean checkIsUnique(ProductUIPageParam aProductUIPageParam) throws Exception {

    if (aProductUIPageParam == null) {
      return true;
    }

    List valueList = new ArrayList();

    List pkValueList = new ArrayList();

    pkValueList.add(aProductUIPageParam.getId());

    return isUnique(
        valueList.toArray(new Object[valueList.size()]),
        pkValueList.toArray(new Object[pkValueList.size()]));
  }

  /**
   * Insert Data
   *
   * @param aProductUIPageParam
   * @throws Exception
   */
  public void insert(ProductUIPageParam aProductUIPageParam) throws Exception {

    super.doInsert(aProductUIPageParam);
  }

  /**
   * Batch Insert Datas
   *
   * @param aProductUIPageParam
   * @throws Exception
   */
  public void batchInsert(ProductUIPageParam[] aProductUIPageParams) throws Exception {

    super.doBatchInsert(aProductUIPageParams);
  }

  /**
   * Delete Data
   *
   * @param final long id *
   * @throws Exception
   */
  public void delete(final long id) throws Exception {

    super.doDeleteById(new Object[] {new Long(id)});
  }

  /**
   * Delete Datas
   *
   * @param queryBean
   * @throws Exception
   */
  public void delete(ProductUIPageParamDAOQueryBean queryBean) throws Exception {

    super.doDeleteByQuery(queryBean);
  }

  public void delete(ProductUIPageParam aProductUIPageParam) throws Exception {

    delete(aProductUIPageParam.getId());
  }

  /**
   * Update Data Selective
   *
   * @param aProductUIPageParam
   * @throws Exception
   */
  public void update(ProductUIPageParam aProductUIPageParam) throws Exception {

    if (aProductUIPageParam.getId() == 0) {
      throw new Exception("Can not update object data whith out primary key value");
    }

    super.doUpdate(aProductUIPageParam);

    ProductUIPageParam tempObj = findById(aProductUIPageParam.getId());

    if (tempObj != null) {
      PropertyUtils.copyProperties(aProductUIPageParam, tempObj);
    }
  }

  /**
   * Batch Update Datas
   *
   * @param aProductUIPageParams[]
   * @throws Exception
   */
  public void batchUpdate(ProductUIPageParam[] aProductUIPageParams) throws Exception {

    super.doBatchUpdate(aProductUIPageParams);
  }

  /**
   * Update Data By Condictions
   *
   * @param aProductUIPageParam
   * @param aValueCriteria
   * @param aTransaction
   * @throws Exception
   */
  public void update(
      ProductUIPageParam aProductUIPageParam, ProductUIPageParamDAOQueryBean aQueryBean)
      throws Exception {

    super.doUpdateByQuery(aProductUIPageParam, aQueryBean);
  }

  /**
   * Update Data By Condictions
   *
   * @param aQueryBean
   * @throws Exception
   */
  public void update(ProductUIPageParamDAOQueryBean aQueryBean) throws Exception {
    super.doUpdateByQuery(aQueryBean);
  }

  protected void checkNullValue(ProductUIPageParam aProductUIPageParam) throws Exception {}

  /**
   * Get Data By ID
   *
   * @param final long id * @return ${businessObject.name}
   * @throws Exception
   */
  public ProductUIPageParam findById(final long id) throws Exception {

    ProductUIPageParamDAOQueryBean queryBean = new ProductUIPageParamDAOQueryBean();

    ProductUIPageParamDAOQueryBean.Criteria criteria = queryBean.createCriteria();

    criteria.andIdEqualTo(id);

    // queryBean.setDistinct(true);

    ProductUIPageParam[] ProductUIPageParams = query(queryBean);

    if (ProductUIPageParams.length == 0) {
      return null;
    } else {
      return ProductUIPageParams[0];
    }
  }

  /**
   * Query Data
   *
   * @param queryBean
   * @return ProductUIPageParam[]
   * @throws Exception
   */
  public ProductUIPageParam[] query(ProductUIPageParamDAOQueryBean queryBean) throws Exception {

    List result = super.doQuery(queryBean, new JdbcProductUIPageParamRowMapper());

    return (ProductUIPageParam[]) result.toArray(new ProductUIPageParam[result.size()]);
  }

  /**
   * Query ${businessObject.name} Selective
   *
   * @param queryBean
   * @return Map[]
   * @model
   * @throws Exception
   */
  public Map<String, Object>[] querySelective(ProductUIPageParamDAOQueryBean queryBean)
      throws Exception {

    if (queryBean.getSelectProperties().isEmpty()) {
      queryBean.addAllSelectProperties();
    }

    return super.doQuerySelective(queryBean);
  }

  /**
   * Query Data Count
   *
   * @param queryBean
   * @return int
   * @throws Exception
   */
  public int queryCount(ProductUIPageParamDAOQueryBean queryBean) throws Exception {

    return super.doQueryCount(queryBean);
  }

  public void synchronize(
      ProductUIPageParam[] aProductUIPageParams, ProductUIPageParamDAOQueryBean queryBean)
      throws Exception {
    daoHelper.synchronize(aProductUIPageParams, queryBean);
  }

  public void synchronize(
      ProductUIPageParam[] aProductUIPageParams,
      ProductUIPageParamDAOQueryBean queryBean,
      net.dao.IDataAccessInterface.ISynchronizeCallback<ProductUIPageParam> callBack)
      throws Exception {
    daoHelper.synchronize(aProductUIPageParams, queryBean, callBack);
  }

  public static class JdbcProductUIPageParamRowMapper implements RowMapper<ProductUIPageParam> {

    public ProductUIPageParam mapRow(ResultSet resultSet, int arg1) throws SQLException {
      ProductUIPageParam object = new ProductUIPageParam();

      int columnIndex = 1;

      int __dataType;

      try {

        Object id = null;

        id = resultSet.getObject(columnIndex++);

        object.setIdNull(resultSet.getBoolean(columnIndex++));

        if (id != null) {

          setBeanValue(object, _DataObjectProperty.Id, id);
        }

        Object pageId = null;

        pageId = resultSet.getObject(columnIndex++);

        object.setPageIdNull(resultSet.getBoolean(columnIndex++));

        if (pageId != null) {

          setBeanValue(object, _DataObjectProperty.PageId, pageId);
        }

        Object pageParamId = null;

        pageParamId = resultSet.getObject(columnIndex++);

        object.setPageParamIdNull(resultSet.getBoolean(columnIndex++));

        if (pageParamId != null) {

          setBeanValue(object, _DataObjectProperty.PageParamId, pageParamId);
        }

        Object pageParamValue = null;

        pageParamValue = resultSet.getObject(columnIndex++);

        object.setPageParamValueNull(resultSet.getBoolean(columnIndex++));

        if (pageParamValue != null) {

          setBeanValue(object, _DataObjectProperty.PageParamValue, pageParamValue);
        }

        Object status = null;

        status = resultSet.getObject(columnIndex++);

        object.setStatusNull(resultSet.getBoolean(columnIndex++));

        if (status != null) {

          setBeanValue(object, _DataObjectProperty.Status, status);
        }

        Object remarks = null;

        remarks = resultSet.getObject(columnIndex++);

        object.setRemarksNull(resultSet.getBoolean(columnIndex++));

        if (remarks != null) {

          setBeanValue(object, _DataObjectProperty.Remarks, remarks);
        }

        Object pageParamValueId = null;

        pageParamValueId = resultSet.getObject(columnIndex++);

        object.setPageParamValueIdNull(resultSet.getBoolean(columnIndex++));

        if (pageParamValueId != null) {

          setBeanValue(object, _DataObjectProperty.PageParamValueId, pageParamValueId);
        }

        Object paramCode = null;

        paramCode = resultSet.getObject(columnIndex++);

        object.setParamCodeNull(resultSet.getBoolean(columnIndex++));

        if (paramCode != null) {

          setBeanValue(object, _DataObjectProperty.ParamCode, paramCode);
        }

        Object paramDesc = null;

        paramDesc = resultSet.getObject(columnIndex++);

        object.setParamDescNull(resultSet.getBoolean(columnIndex++));

        if (paramDesc != null) {

          setBeanValue(object, _DataObjectProperty.ParamDesc, paramDesc);
        }

        Object paramInputType = null;

        paramInputType = resultSet.getObject(columnIndex++);

        object.setParamInputTypeNull(resultSet.getBoolean(columnIndex++));

        if (paramInputType != null) {

          setBeanValue(object, _DataObjectProperty.ParamInputType, paramInputType);
        }

        return object;
      } catch (Exception e) {
        throw new SQLException(e.getMessage());
      }
    }
  }
}
